// 这里是用来进行数据库操作的
let { conn } = require('../gather/mongo')
// 查看数据库中的数据
exports.findUsers = (username, callback) => {
    let sql = `SELECT * FROM user_info WHERE username = '${username}'`
    conn.query(sql, (err, result) => {
        if (err) {
            console.log(err)
        } else {
            callback(result)
        }
    })
}
// 先数据库中插入一条数据
exports.insertUsers = (info, callback) => {
    // 向数据库插入一条数据
    const sql = `INSERT INTO user_info (username,password,bg_url,roles) VALUES 
    ('${info.username}','${info.password}','https://zenvideo.gtimg.com/xy/zen_video/bgimg/thumb/Y2IogDpn.jpg','用户')`
    conn.query(sql, (err, result) => {
        if (err) {
            console.log(err)
        } else {
            callback(result)
        }
    })
}
// 根据id查看数据库中的数据
exports.findUsersId = (id, callback) => {
    const sql = `SELECT * FROM user_info WHERE id = ${id}`
    conn.query(sql, (err, result) => {
        if (err) {
            console.log(err)
        } else {
            callback(result)
        }
    })
}
// 根据id查看数据库中的数据
exports.updataUsersInfo = (data, callback) => {
    const sql = `UPDATE user_info SET  
    username = '${data.username}'
    ,nickname = '${data.nickname}'
    ,roles = '${data.roles}',age = '${data.age}'
    ,sex = '${data.sex}'
    ,phone = '${data.phone}',
    signature = '${data.signature}'
    WHERE id = ${data.id}`

    conn.query(sql, (err, result) => {
        if (err) {
            console.log(err)
        } else {
            callback(result)
        }
    })
}


